﻿using Basic.HrCollect;
using Basic.HrModel.DB;
using Basic.HrRemoteModel.Power.Model;
using Basic.HrService.Interface;
using WeDonekRpc.Client;

namespace Basic.HrService.lmpl
{
    internal class AppPowerService : IAppPowerService
    {
        private readonly IPowerCollect _Power;

        public AppPowerService ( IPowerCollect power )
        {
            this._Power = power;
        }

        public bool Save ( string linkType, long linkPk, PowerSet set )
        {
            DBPowerList power = this._Power.Find<DBPowerList>(linkType, linkPk);
            if ( power == null )
            {
                _ = this._Power.Add(set, linkType, linkPk);
                return true;
            }
            return this._Power.Set(power, set);
        }
        public void Delete ( string linkType, long linkPk )
        {
            DBPowerList power = this._Power.Find<DBPowerList>(linkType, linkPk);
            if ( power == null )
            {
                return;
            }
            this._Power.Delete(power);
        }
        public PowerData Get ( string linkType, long linkPk )
        {
            DBPowerList power = this._Power.Find<DBPowerList>(linkType, linkPk);
            if ( power == null )
            {
                return null;
            }
            return power.ConvertMap<DBPowerList, PowerData>();
        }
        public bool SetIsEnable ( string linkType, long linkPk, bool isEnable )
        {
            DBPowerList power = this._Power.Find<DBPowerList>(linkType, linkPk);
            if ( power == null )
            {
                return false;
            }
            return this._Power.SetIsEnable(power, isEnable);
        }
    }
}
